/* 
 * Copyright 2013 Sébastien Mouquet.
 * 
 * This file is part of ECovoiturage.
 * 
 * ECovoiturage is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ECovoiturage is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ECovoiturage. If not, see http://www.gnu.org/licenses/.
 */
package com.smouquet.ecovoiturage.core.domain;

import java.io.Serializable;
import java.sql.Time;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author sebastien.mouquet
 */
@Entity
@Table(name="trajet")
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="dtype")
public class Trajet implements Serializable
{
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id", nullable=false)
    private Integer id;
    
    @Column(name="dtype", nullable=false, length=50)
    private String dtype;
    
    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="fk_created_by", nullable=false)
    private Utilisateur createdBy;
    
    @Column(name="jour")
    @Temporal(TemporalType.DATE)
    private Date jour;
    
    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn(name="fk_lieu_depart", nullable=false)
    private Lieu lieuDepart;
    
    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn(name="fk_lieu_arrivee", nullable=false)
    private Lieu lieuArrivee;
    
    @Column(name="heure_depart", nullable=false)
    private Time heureDepart;
    
    @Column(name="heure_retour")
    private Time heureRetour;
    
    @Column(name="informations")
    private String informations;
    
    @OneToMany(mappedBy="trajet", fetch=FetchType.EAGER, cascade= CascadeType.ALL)
    private List<TrajetUtilisateur> interesses;
    
    @OneToMany(mappedBy="trajet", fetch=FetchType.EAGER, cascade= CascadeType.ALL)
    private List<TrajetCommentaire> commentaires;
    
    
    public Trajet() {}
    

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getDtype() {
        return dtype;
    }

    public void setDtype(String dtype) {
        this.dtype = dtype;
    }

    public Utilisateur getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Utilisateur createdBy) {
        this.createdBy = createdBy;
    }

    public Date getJour() {
        return jour;
    }

    public void setJour(Date jour) {
        this.jour = jour;
    }

    public Lieu getLieuDepart() {
        return lieuDepart;
    }

    public void setLieuDepart(Lieu lieuDepart) {
        this.lieuDepart = lieuDepart;
    }

    public Lieu getLieuArrivee() {
        return lieuArrivee;
    }

    public void setLieuArrivee(Lieu lieuArrivee) {
        this.lieuArrivee = lieuArrivee;
    }

    public Time getHeureDepart() {
        return heureDepart;
    }

    public void setHeureDepart(Time heureDepart) {
        this.heureDepart = heureDepart;
    }

    public Time getHeureRetour() {
        return heureRetour;
    }

    public void setHeureRetour(Time heureRetour) {
        this.heureRetour = heureRetour;
    }

    public String getInformations() {
        return informations;
    }

    public void setInformations(String informations) {
        this.informations = informations;
    }

    public List<TrajetUtilisateur> getInteresses() {
        return interesses;
    }

    public void setInteresses(List<TrajetUtilisateur> interesses) {
        this.interesses = interesses;
    }

    public List<TrajetCommentaire> getCommentaires() {
        return commentaires;
    }

    public void setCommentaires(List<TrajetCommentaire> commentaires) {
        this.commentaires = commentaires;
    }
}
